package com.mokairui.http;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @Description com.sunshine.http
 * @Author Mokairui
 * @Since 2022/1/11
 */
public class HttpNettyServer {

    public static void main(String[] args) throws InterruptedException {

        NioEventLoopGroup boss = new NioEventLoopGroup(1);
        NioEventLoopGroup worker = new NioEventLoopGroup(1);

        try {
            ServerBootstrap serverBootstrap = new ServerBootstrap();
            serverBootstrap.group(boss, worker);
//            serverBootstrap.option(ChannelOption.SO_BACKLOG, 128);
//            serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
            serverBootstrap.channel(NioServerSocketChannel.class);
            serverBootstrap.childHandler(new SimpleHttpChannelInitializer());

            ChannelFuture channelFuture = serverBootstrap.bind(8080).sync();

            channelFuture.channel().closeFuture().sync();
        } finally {
            boss.shutdownGracefully();
            worker.shutdownGracefully();
        }

    }

}
